﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace B13_Ex03_David_300512340_Alexey_321203689.ChainOfResp
{
    /// <summary>
    /// Pattern: Chain of responsibility.
    /// Role: ConcreteHandler.
    /// Responsible for loading events of selected friend.
    /// 1. Handles requests it is responsible for.
    /// 2. Can access its successor.
    /// 3. If the ConcreteHandler can handle the request,
    ///    it does so; otherwise it forwards the request to its successor.
    /// </summary>
    public class ListBoxEvents : Handler
    {
        private ListBox m_ListBoxEvents;

        public ListBoxEvents(ref ListBox io_ListBoxEvents)
        {
            m_ListBoxEvents = io_ListBoxEvents;
        }

        public override void ProcessRequest(UserWrapper i_SelectedFriend)
        {
            if (i_SelectedFriend.UserInformation.Events.Count != 0)
            {
                m_ListBoxEvents.DisplayMember = string.Format("Name");
                m_ListBoxEvents.DataSource = i_SelectedFriend.GetEventsList();
            }
            else
            {
                m_ListBoxEvents.DataSource = null;
                m_ListBoxEvents.Items.Clear();
            }

            if (m_Successor != null)
            {
                m_Successor.ProcessRequest(i_SelectedFriend);
            }
        }
    }
}
